// MCKit
// Copyright (c) 2010, Hz Systems LLC
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//	•Redistributions of source code must retain the above copyright notice,
//	 this list of conditions and the following disclaimer.
//	•Redistributions in binary form must reproduce the above copyright notice,
//	 this list of conditions and the following disclaimer in the documentation and/or
//	 other materials provided with the distribution.
//	•Neither the name of Aquatic nor the names of its contributors may be used to 
//	 endorse or promote products derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#import <Foundation/Foundation.h>

typedef enum NBTTagType
{
	kNBTTagType_END = 0,
	kNBTTagType_BYTE = 1,
	kNBTTagType_SHORT = 2,
	kNBTTagType_INT = 3,
	kNBTTagType_LONG = 4,
	kNBTTagType_FLOAT = 5,
	kNBTTagType_DOUBLE = 6,
	kNBTTagType_BYTE_ARRAY = 7,
	kNBTTagType_STRING = 8,
	kNBTTagType_LIST = 9,
	kNBTTagType_COMPOUND = 10
} NBTTagType;

@class NBTTag;
@interface NBTData : NSObject
{
	NSMutableData	*_data;
	size_t	_dataSize;
	uint8_t *_dataptr;
	size_t	_cursor;
}
@property(readonly) NSData *data;

-(id)initWithFile:(NSString*)filePath;
-(id)readTag;
-(void)writeTag:(NSMutableData*)inTarget tag:(NBTTag*)inValue;
@end


#pragma mark -


@interface NBTTag : NSObject
{
	NBTTagType _type;
	NSString *_name;
	id	_value;
}
@property(retain) NSString *name;
@property(retain) id value;
@property(assign) NBTTagType type;

-(id)initWithName:(NSString*)inName;
-(void)writeToFile:(NSString*)path;
@end

@interface NBTByteTag : NBTTag
-(id)initWithName:(NSString *)inName byteValue:(int8_t)inValue;
-(id)initWithByte:(int8_t)inValue;
@end

@interface NBTShortTag : NBTTag
-(id)initWithName:(NSString *)inName shortValue:(int16_t)inValue;
@end

@interface NBTIntTag : NBTTag
-(id)initWithName:(NSString *)inName intValue:(int32_t)inValue;
@end

@interface NBTLongTag : NBTTag
-(id)initWithName:(NSString *)inName longValue:(int64_t)inValue;
@end

@interface NBTFloatTag : NBTTag
-(id)initWithName:(NSString *)inName floatValue:(float)inValue;
@end

@interface NBTDoubleTag : NBTTag
-(id)initWithName:(NSString *)inName doubleValue:(double)inValue;
@end

@interface NBTByteArrayTag : NBTTag
-(id)initWithName:(NSString *)inName bytes:(void*)inBytes length:(uint32_t)inLength;
@end

@interface NBTStringTag : NBTTag
-(id)initWithName:(NSString *)inName string:(NSString*)inString;
@end

@interface NBTListTag : NBTTag
{
	NSString *tagType;
}
@property(retain) NSString *tagType;
-(id)initWithTags:(NSArray*)inTags;
-(id)initWithName:(NSString *)inName className:(NSString*)inClassName list:(NSArray*)inList;
-(id)initWithName:(NSString *)inName class:(Class)inClassName list:(NSArray*)inList;
@end

@interface NBTCompoundTag : NBTTag
{
}
-(id)initWithTags:(NSDictionary*)inTags;
-(id)initWithName:(NSString *)inName map:(NSDictionary*)inMap;
-(void)addChild:(NBTTag*)inTag;
-(id)tagWithName:(NSString*)inKey;
@end

@interface NBTEndTag : NBTTag
@end

